﻿var status = 0;
var choice;
var scrolls = Array(
Array("", 1402029, 0),
Array("", 1402030, 0),
Array("", 1402031, 0),
Array("", 1402032, 0),
Array("", 1402033, 0),
Array("", 1402034, 0),
Array("", 1402035, 0),
Array("", 1402036, 0),
Array("", 1402037, 0),
Array("", 1402039, 0),
Array("", 1402040, 0),
Array("", 1402041, 0),
Array("", 1402042, 0),
Array("", 1402043, 0),
Array("", 1402044, 0),
Array("", 1402046, 0),
Array("", 1402047, 0),
Array("", 1402049, 0),
Array("", 1402053, 0),
Array("", 1402054, 0),
Array("", 1402055, 0),
Array("", 1402056, 0),
Array("", 1402057, 0),
Array("", 1402058, 0),
Array("", 1402059, 0),
Array("", 1402062, 0),
Array("", 1402063, 0),
Array("", 1402064, 0),
Array("", 1402068, 0),
Array("", 1402072, 0),
Array("", 1402073, 0),
Array("", 1402074, 0),
Array("", 1402075, 0),
Array("", 1402076, 0),
Array("", 1402077, 0),
Array("", 1402078, 0),
Array("", 1402081, 0),
Array("", 1402084, 0),
Array("", 1402085, 0),
Array("", 1402086, 0),
Array("", 1402087, 0),
Array("", 1402088, 0),
Array("", 1402089, 0),
Array("", 1402090, 0),
Array("", 1402091, 0),
Array("", 1402092, 0),
Array("", 1402093, 0),
Array("", 1402094, 0),
Array("", 1402095, 0),
Array("", 1402096, 0),
Array("", 1402097, 0),
Array("", 1402098, 0),
Array("", 1402099, 0),
Array("", 1402100, 0),
Array("", 1402101, 0),
Array("", 1402102, 0),
Array("", 1402103, 0),
Array("", 1402104, 0),
Array("", 1402105, 0),
Array("", 1402106, 0),
Array("", 1402107, 0),
Array("", 1402109, 0),
Array("", 1402111, 0),
Array("", 1402112, 0),
Array("", 1402113, 0),
Array("", 1402114, 0),
Array("", 1402115, 0),
Array("", 1402116, 0),
Array("", 1402117, 0),
Array("", 1402118, 0),
Array("", 1402119, 0),
Array("", 1402120, 0),
Array("", 1402121, 0),
Array("", 1402122, 0),
Array("", 1402123, 0),
Array("", 1402124, 0),
Array("", 1402125, 0),
Array("", 1402126, 0),
Array("", 1402127, 0),
Array("", 1402128, 0),
Array("", 1402129, 0),
Array("", 1402130, 0),
Array("", 1402131, 0),
Array("", 1402133, 0),
Array("", 1402134, 0),
Array("", 1402135, 0),
Array("", 1402136, 0),
Array("", 1402137, 0),
Array("", 1402138, 0),
Array("", 1402142, 0),
Array("", 1402143, 0),
Array("", 1402145, 0),
Array("", 1402146, 0),
Array("", 1402147, 0),
Array("", 1402148, 0),
Array("", 1402149, 0),
Array("", 1402150, 0),
Array("", 1402151, 0),
Array("", 1402152, 0),
Array("", 1402154, 0),
Array("", 1402155, 0),
Array("", 1402172, 0),
Array("", 1402174, 0),
Array("", 1402175, 0),
Array("", 1402176, 0),
Array("", 1402177, 0),
Array("", 1402178, 0),
Array("", 1402179, 0),
Array("", 1402184, 0),
Array("", 1402185, 0),
Array("", 1412000, 0),
Array("", 1412001, 0),
Array("", 1412002, 0),
Array("", 1412003, 0),
Array("", 1412004, 0),
Array("", 1412005, 0),
Array("", 1412006, 0),
Array("", 1412007, 0),
Array("", 1412008, 0),
Array("", 1412009, 0),
Array("", 1412010, 0),
Array("", 1412011, 0),
Array("", 1412012, 0),
Array("", 1412013, 0),
Array("", 1412014, 0),
Array("", 1412015, 0),
Array("", 1412016, 0),
Array("", 1412017, 0),
Array("", 1412018, 0),
Array("", 1412019, 0),
Array("", 1412020, 0),
Array("", 1412021, 0),
Array("", 1412022, 0),
Array("", 1412023, 0),
Array("", 1412024, 0),
Array("", 1412025, 0),
Array("", 1412026, 0),
Array("", 1412027, 0),
Array("", 1412028, 0),
Array("", 1412029, 0),
Array("", 1412030, 0),
Array("", 1412031, 0),
Array("", 1412033, 0),
Array("", 1412034, 0),
Array("", 1412035, 0),
Array("", 1412036, 0),
Array("", 1412037, 0),
Array("", 1412038, 0),
Array("", 1412039, 0),
Array("", 1412040, 0),
Array("", 1412042, 0),
Array("", 1412043, 0),
Array("", 1412044, 0),
Array("", 1412046, 0),
Array("", 1412047, 0),
Array("", 1412048, 0),
Array("", 1412051, 0),
Array("", 1412054, 0),
Array("", 1412055, 0),
Array("", 1412056, 0),
Array("", 1412057, 0),
Array("", 1412058, 0),
Array("", 1412059, 0),
Array("", 1412060, 0),
Array("", 1412061, 0),
Array("", 1412062, 0),
Array("", 1412063, 0),
Array("", 1412064, 0),
Array("", 1412065, 0),
Array("", 1412066, 0),
Array("", 1412067, 0),
Array("", 1412068, 0),
Array("", 1412070, 0),
Array("", 1412071, 0),
Array("", 1412072, 0),
Array("", 1412073, 0),
Array("", 1412074, 0),
Array("", 1412075, 0),
Array("", 1412076, 0),
Array("", 1412077, 0),
Array("", 1412078, 0),
Array("", 1412079, 0),
Array("", 1412080, 0),
Array("", 1412081, 0),
Array("", 1412082, 0),
Array("", 1412083, 0),
Array("", 1412084, 0),
Array("", 1412085, 0),
Array("", 1412086, 0),
Array("", 1412087, 0),
Array("", 1412089, 0),
Array("", 1412090, 0),
Array("", 1412091, 0),
Array("", 1412092, 0),
Array("", 1412093, 0),
Array("", 1412094, 0),
Array("", 1412099, 0),
Array("", 1412100, 0),
Array("", 1412102, 0),
Array("", 1412103, 0),
Array("", 1412104, 0),
Array("", 1412105, 0),
Array("", 1412107, 0),
Array("", 1412108, 0),
Array("", 1412122, 0),
Array("", 1412123, 0),
Array("", 1412124, 0),
Array("", 1412125, 0),
Array("", 1412126, 0)
);

function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (mode == -1) cm.dispose();
    else {
        if (status == 0 && mode == 0) {
            cm.dispose();
            return;
        } else if (status >= 1 && mode == 0) {
            cm.sendOk("好吧，欢迎下次继续光临！.");
            cm.dispose();
            return;
        }
        if (mode == 1) status++;
        else status--;

        if (status == 0) {
            choices = "\r\n兔兔币余额：#r" + cm.getHyPay(1) + "#k个 (#r买后不支持退货哟亲#k)";
            for (var i = 0; i < scrolls.length; i++) {
                choices += "\r\n#L" + i + "##v" + scrolls[i][1] + "##z" + scrolls[i][1] + "#　#d需要#r" + scrolls[i][2] + "#d兔兔币#k#l";
            }
            cm.sendSimpleS("欢迎来到双手剑,斧店,你想买我们商店的物品么?请选择吧：." + choices,2);
        } else if (status == 1) {
            cm.sendYesNo("你确定需要购买#v" + scrolls[selection][1] + "##t" + scrolls[selection][1] + "#?");
		choice = selection;
        } else if (status == 2) {
            var money = scrolls[choice][2];
            if (cm.getHyPay(1) < money) {
                cm.sendOk("抱歉，你没足够的兔兔币！");
                cm.dispose();
            } else {
                cm.addHyPay(money);
                cm.gainItem(scrolls[choice][1], 1);
                cm.sendOk("购买成功.");
                cm.dispose();
            }
        }
    }
}